Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
25.00% |
1 / 4 |
CRAP | |
69.23% |
18 / 26 |
| FirewallMap | |
0.00% |
0 / 1 |
|
25.00% |
1 / 4 |
19.71 | |
69.23% |
18 / 26 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| getListeners | |
0.00% |
0 / 1 |
2.06 | |
75.00% |
3 / 4 |
|||
| getFirewallContext | |
0.00% |
0 / 1 |
14.18 | |
60.00% |
9 / 15 |
|||
| isSSOEnabled | |
0.00% |
0 / 1 |
2.06 | |
75.00% |
3 / 4 |
|||
| <?php | |
| declare(strict_types=1); | |
| namespace Akeneo\Platform\Bundle\AuthenticationBundle\Sso; | |
| use Akeneo\Platform\Component\Authentication\Sso\Configuration\Persistence\ConfigurationNotFound; | |
| use Akeneo\Platform\Component\Authentication\Sso\Configuration\Persistence\Repository; | |
| use Symfony\Component\HttpFoundation\Request; | |
| use Symfony\Component\Security\Http\FirewallMapInterface; | |
| class FirewallMap implements FirewallMapInterface | |
| { | |
| private const CONFIGURATION_CODE = 'authentication_sso'; | |
| private const SSO_FIREWALL_NAME = 'sso'; | |
| /** @var FirewallMapInterface */ | |
| private $firewallMap; | |
| /** @var Repository */ | |
| private $configRepository; | |
| public function __construct(FirewallMapInterface $firewallMap, Repository $configRepository) | |
| { | |
| $this->firewallMap = $firewallMap; | |
| $this->configRepository = $configRepository; | |
| } | |
| public function getListeners(Request $request) | |
| { | |
| $context = $this->getFirewallContext($request); | |
| if (null === $context) { | |
| return [[], null]; | |
| } | |
| return [$context->getListeners(), $context->getExceptionListener(), $context->getLogoutListener()]; | |
| } | |
| private function getFirewallContext(Request $request) | |
| { | |
| if ($request->attributes->has('_firewall_context')) { | |
| $storedContextId = $request->attributes->get('_firewall_context'); | |
| foreach ($this->firewallMap->map as $contextId => $requestMatcher) { | |
| if ($contextId === $storedContextId) { | |
| return $this->firewallMap->container->get($contextId); | |
| } | |
| } | |
| $request->attributes->remove('_firewall_context'); | |
| } | |
| foreach ($this->firewallMap->map as $contextId => $requestMatcher) { | |
| if (null === $requestMatcher || $requestMatcher->matches($request)) { | |
| $request->attributes->set('_firewall_context', $contextId); | |
| $contextService = $this->firewallMap->container->get($contextId); | |
| if (self::SSO_FIREWALL_NAME === $contextService->getConfig()->getName() | |
| && !$this->isSSOEnabled() | |
| ) { | |
| continue; | |
| } | |
| return $contextService; | |
| } | |
| } | |
| } | |
| private function isSSOEnabled(): bool | |
| { | |
| try { | |
| $config = $this->configRepository->find(self::CONFIGURATION_CODE); | |
| } catch (ConfigurationNotFound $e) { | |
| return false; | |
| } | |
| return $config->isEnabled(); | |
| } | |
| } |